package com.bootcamp.s2_0922.ds.Exercise._0929_Ex;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @program: myClassCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-29 20:35
 **/

public class Ex2_RedBlueBall {
    static final int RED_NUM = 6;

    public static void main(String[] args) {
        // 随机数对象
        Random random = new Random();
        // list 对象
        List<Integer> balls = new ArrayList<>(10);
        // 记录红色小球个数
        int redCount = 0;
        while (redCount < RED_NUM) {
            int red = random.nextInt(33) + 1;
            if (balls.contains(red))
                // 当已经包含该红球时候，红球不添加，继续产生下一个随机数
                continue;
            balls.add(red);
            redCount++;

        }
        // 添加蓝色球
        balls.add(random.nextInt(16) + 1);
        int ballCount = 0;
        for (Integer ball : balls) {
            if (ballCount++ < RED_NUM) {
                // 输出红色
                System.out.printf("\033[1;31m");
            } else {
                // 输出蓝色
                System.out.printf("\033[1;34m");
            }
            System.out.print(ball + " ");
        }
        System.out.println();
    }
}
